<?php
/**
 * Created by PhpStorm.
 * User: zhd
 * Date: 2018/10/11
 * Time: 21:47
 */

namespace app\Module\Index\Controller;


use app\Module\Index\Logic\MessageLogic;
use app\Module\Index\Logic\MessageType;
use app\Module\Index\Model\ArticleCollectModel;
use app\Module\Index\Model\ArticleImageModel;
use app\Module\Index\Model\ArticleModel;
use app\Module\Index\Model\ArticleRecommendModel;
use app\Module\Index\Model\ArticleTypeModel;
use app\Module\Index\Model\ArticleVideoModel;
use app\Module\Index\Model\LogArticleLookModel;
use app\Module\Index\Model\LogArticleShareModel;
use app\Module\Index\Model\UserModel;
use FFMpeg\Coordinate\TimeCode;
use FFMpeg\FFMpeg;
use framework\controller\Controller;

class ArticleController extends Controller
{
    private $videoPath    = APP_PATH . '/upload/video/';
    private $ignoreTypeId = '3';

    /**
     * 获取最新列表
     *
     * @verify int|null $page
     * @verify int|null $limit
     * @return string
     */
    public function getNewListAction($page = 1, $limit = 20)
    {
        $articleModel = new ArticleModel();
        $articleModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.longitude,user.type as user_type,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,GROUP_CONCAT(DISTINCT article_video.url) as video,article_video.frame_url");
        $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleModel->setJoin('user', 'user.id= article.user_id');
        $articleModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleModel->addWhere('article.updated', date("Y-m-d", strtotime("-1 month")), '>=');

        $articleModel->setPage($page, $limit);
        $articleModel->addOrder('article.updated', false);
        $articleModel->addWhere('one_type.id', 5, '!=');
        $articleModel->addWhere([
            'article.is_hide'  => 0,
            'one_type.is_hide' => 0,
            'two_type.is_hide' => 0,
            'article.is_del'   => 0,
            'user.type'        => 0,
        ]);
        $articleModel->addGroup('article.id');
        $data = $articleModel->select();

        return success($data);
    }

    /**
     * 获取最热文章
     *
     * @verify int|null $page
     * @verify int|null $limit
     * @return string
     */
    public function getHotAction($page = 1, $limit = 20, $version)
    {
        $articleModel = new ArticleModel();
        $articleModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.longitude,user.type as user_type,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,article_video.url as video,article_video.frame_url");
        $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleModel->setJoin('user', 'user.id= article.user_id');
        $articleModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleModel->setPage($page, $limit);
        $articleModel->addOrder(['article.share_num', 'article.collect_num', 'article.comment_num', 'article.look_num'], false);
        $articleModel->addWhere('article.updated', date("Y-m-d", strtotime("-1 month")), '>=');
        $articleModel->addWhere('one_type.id', 5, '!=');
        $articleModel->addWhere([
            'article.is_hide'  => 0,
            'one_type.is_hide' => 0,
            'two_type.is_hide' => 0,
            'article.is_del'   => 0,
            'user.type'        => 0,
        ]);
        $articleModel->addGroup('article.id');
        $data = $articleModel->select();

        return success($data);
    }

    /**
     * 获取推荐文章
     *
     * @verify int|null $page
     * @verify int|null $limit
     * @return string
     */
    public function getRecommendAction($page = 1, $limit = 20)
    {
        if ($page < 1) {
            $page = 1;
        }
        $articleRecommendModel = new ArticleRecommendModel();
        $articleRecommendModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.type as user_type,user.longitude,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,article_video.url as video,article_video.frame_url");
        $articleRecommendModel->setJoin('article', 'article.id= article_recommend.article_id');
        $articleRecommendModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleRecommendModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleRecommendModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleRecommendModel->setJoin('user', 'user.id= article.user_id');
        $articleRecommendModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleRecommendModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleRecommendModel->addWhere('article.updated', date("Y-m-d", strtotime("-1 month")), '>=');
        $articleRecommendModel->setPage($page, $limit);
        $articleRecommendModel->addOrder('article.updated', false);
        $articleRecommendModel->addWhere([
            'article.is_hide'  => 0,
            'one_type.is_hide' => 0,
            'two_type.is_hide' => 0,
            'article.is_del'   => 0,
        ]);
        $articleRecommendModel->addGroup('article.id');
        $data = $articleRecommendModel->select();

        return success($data);
    }

    /**
     * 获取平台发布
     *
     * @verify int|null $page
     * @verify int|null $limit
     * @return string
     */
    public function getTerraceRecommendAction($page = 1, $limit = 20)
    {
        $articleModel = new ArticleModel();
        $articleModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.type as user_type,user.longitude,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,GROUP_CONCAT(DISTINCT article_video.url) as video,article_video.frame_url");
        $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleModel->setJoin('user', 'user.id= article.user_id');
        $articleModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleModel->addWhere('article.updated', date("Y-m-d", strtotime("-1 month")), '>=');

        $articleModel->setPage($page, $limit);
        $articleModel->addOrder('article.updated', false);
        $articleModel->addWhere([
            'article.is_hide'  => 0,
            'one_type.is_hide' => 0,
            'two_type.is_hide' => 0,
            'article.is_del'   => 0,
            'user.type'        => 1,
        ]);
        $articleModel->addGroup('article.id');
        $data = $articleModel->select();

        foreach ($data as $key => $datum) {
            if ($datum['user_type'] == '1') {
                $data[$key]['mobile']       = '0';
                $data[$key]['latitude']     = null;
                $data[$key]['longitude']    = null;
                $data[$key]['address_name'] = '';
            }
        }

        return success($data);
    }

    /**
     * 根据类型获取文章列表
     *
     * @verify int        $oneTypeId
     * @verify array|null $towTypeId
     * @verify int|null   $mode
     * @verify int|null   $page
     * @verify int|null   $limit
     * @return string
     */
    public function getListByTypeAction($oneTypeId, $towTypeId, $mode = 0, $page = 1, $limit = 20)
    {
        $articleModel = new ArticleModel();
        $articleModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.type as user_type,user.longitude,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,article_video.url as video,article_video.frame_url");
        $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleModel->setJoin('user', 'user.id= article.user_id');
        $articleModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleModel->addWhere('article.updated', date("Y-m-d", strtotime("-1 month")), '>=');
        $articleModel->setPage($page, $limit);

        $articleModel->addWhere([
            'article.is_hide'  => 0,
            'one_type.is_hide' => 0,
            'two_type.is_hide' => 0,
            'article.is_del'   => 0,
        ]);

        $articleModel->addWhere('article_type.one_type_id', $oneTypeId);
        if (!empty($towTypeId)) {
            $articleModel->addWhere('article_type.two_type_id', $towTypeId);
        }
        if ($mode == 0) {
            $articleModel->addOrder('article.updated', false);
        } else {
            $articleModel->addOrder('article.look_num', false);
        }

        $articleModel->addGroup('article.id');
        $data = $articleModel->select();

        foreach ($data as $key => $datum) {
            if ($datum['user_type'] == '1') {
                $data[$key]['mobile']       = '0';
                $data[$key]['latitude']     = '0';
                $data[$key]['longitude']    = '0';
                $data[$key]['address_name'] = '';
            }
        }

        return success($data);
    }

    /**
     * 发布文章
     *
     * @aop    start checkAuth
     *
     * @verify array|null  $images
     * @verify string|null $video
     * @verify string      $content
     * @verify int         $oneTypeId
     * @verify array       $twoTypeId
     * @return string
     */
    public function addAction($images, $video, $content, $oneTypeId, $twoTypeId)
    {
        $userModel = new UserModel();
        $data      = $userModel->row([
            'id' => session('userId'),
        ]);
        if (strtotime($data['black_time']) > time()) {
            return fail('由于您最近有违规记录，管理员已对您限制发布，时间持续至' . $data['black_time']);
        }

        $imageData = [];
        $images    = is_array($images) ? array_filter($images) : [];

        $articleModel = new ArticleModel();
        $articleModel->addWhere('created', now('Y-m-d'), '>=');
        $count = $articleModel->count('1', [
            'user_id' => session('userId'),
            'is_del'  => 0,
            'is_hide' => 0,
        ]);
        if ($count > 1 && $data['type'] == 0) {
            return fail('平台每日限制发布2条信息，往后可能会对限制进行上调!');
        }


        $articleId = $articleModel->insert([
            'content'       => $content,
            'created'       => now(),
            'updated'       => now(),
            'user_id'       => session('userId'),
            'resource_type' => empty($video) ? 0 : 1,
        ]);

        // 添加图片
        foreach ($images as $image) {
            if ($image == '') continue;
            $imageData[] = [
                'article_id' => $articleId,
                'created'    => now(),
                'url'        => $image,
            ];
        }
        if (count($imageData)) {
            $articleImageModel = new ArticleImageModel();
            $articleImageModel->insert($imageData);
        }

        // 添加视频
        if (!empty($video)) {
            $articleVideoModel = new ArticleVideoModel();

            // 添加视频缩略图
            $ffmpeg    = FFMpeg::create([
                'ffmpeg.binaries'  => '/usr/bin/ffmpeg',
                'ffprobe.binaries' => '/usr/bin/ffprobe',
                'timeout'          => 3600, // The timeout for the underlying process
                'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
            ]);
            $videoObj  = $ffmpeg->open(APP_PATH . str_replace('https://www.clocir.com', '', $video));
            $imageName = basename($video, ".mp4");
            $imageUrl  = $this->videoPath . $imageName;
            $videoObj->frame(TimeCode::fromSeconds(1))->save($imageUrl . '.jpg');

            $articleVideoModel->insert([
                'article_id' => $articleId,
                'created'    => now(),
                'url'        => $video,
                'frame_url'  => 'https://www.clocir.com/upload/video/' . $imageName . '.jpg',
            ]);
        }

        // 添加分类
        $articleTypeModel = new ArticleTypeModel();
        $articleTypes     = [];
        foreach ($twoTypeId as $tid) {
            if ($tid == '') continue;
            $articleTypes[] = [
                'article_id'  => $articleId,
                'one_type_id' => $oneTypeId,
                'two_type_id' => $tid,
            ];
        }
        $articleTypeModel->insert($articleTypes);

        return success($articleId);
    }

    /**
     * 添加文章浏览量
     *
     * @verify int $article_id
     * @return string
     */
    public function addLookNumAction($article_id)
    {
        $userId = session('userId');
        if (empty($userId)) {
            return success();
        }

        $logArticleLookModel = new LogArticleLookModel();
        $logArticleLookModel->addWhere('created', date("Y-m-d", strtotime("-1 hour")), '>=');
        $logArticleLookModel->addWhere([
            'article_id' => $article_id,
            'user_id'    => $userId,
        ]);
        $lookNum = $logArticleLookModel->count('1', null, 600);
        // 每个用户每小时只能增加一个
        if ($lookNum > 0) {
            return success();
        }

        $logArticleLookModel->insert([
            'article_id' => $article_id,
            'user_id'    => $userId,
            'created'    => now(),
        ]);
        $articleModel = new ArticleModel();
        $articleModel->update('look_num=look_num+1', ['id' => $article_id]);
        return success();
    }

    /**
     * 添加文章分享量
     *
     * @aop    start checkAuth
     *
     * @verify int $article_id
     * @return string
     */
    public function addShareNumAction($article_id)
    {
        $logArticleShareModel = new LogArticleShareModel();
        $logArticleShareModel->addWhere('created', date("Y-m-d", strtotime("-1 hour")), '>=');
        $logArticleShareModel->addWhere([
            'article_id' => $article_id,
            'user_id'    => session('userId'),
        ]);
        $shareNum = $logArticleShareModel->count('1', null, 600);
        // 每个用户每小时只能增加一个
        if ($shareNum > 0) {
            return success();
        }

        $logArticleShareModel->insert([
            'article_id' => $article_id,
            'user_id'    => session('userId'),
            'created'    => now(),
        ]);

        $articleModel = new ArticleModel();
        $data         = $articleModel->row([
            'id' => $article_id,
        ]);

        $messageLogic = new MessageLogic();
        $messageLogic->add(session('userId'), $data['user_id'], $article_id, MessageType::ARTICLE_SHARE, $data['content']);


        $articleModel->update('share_num=share_num+1', ['id' => $article_id]);
        return success();
    }

    /**
     * 检查是否收藏
     *
     * @aop    start checkAuth
     *
     * @verify int $article_id
     * @return string
     */
    public function chuckCollectAction($article_id)
    {
        $articleCollectModel = new ArticleCollectModel();
        $articleCollectModel->addWhere([
            'article_id' => $article_id,
            'user_id'    => session('userId'),
        ]);
        $data = $articleCollectModel->row();
        if (empty($data)) {
            return success(false);
        } else {
            return success(true);
        }
    }

    /**
     * 收藏
     *
     * @aop    start checkAuth
     *
     * @verify int $article_id
     * @return string
     */
    public function addCollectAction($article_id)
    {
        $articleModel = new ArticleModel();
        $articleData  = $articleModel->row([
            'id' => $article_id,
        ]);

        $articleCollectModel = new ArticleCollectModel();
        $articleCollectModel->addWhere([
            'article_id' => $article_id,
            'user_id'    => session('userId'),
        ]);
        $data = $articleCollectModel->row();

        if (empty($data)) {
            $articleCollectModel->insert([
                'article_id' => $article_id,
                'user_id'    => session('userId'),
                'created'    => now(),
            ]);

            $articleModel->update('collect_num =collect_num+1', [
                'id' => $article_id,
            ]);

            $messageLogic = new MessageLogic();
            $messageLogic->add(session('userId'), $articleData['user_id'], $article_id, MessageType::ARTICLE_COLLECT, $articleData['content']);

            return success(true);
        } else {
            $articleCollectModel->delete([
                'article_id' => $article_id,
                'user_id'    => session('userId'),
            ]);
            $articleModel->update('collect_num =collect_num-1', [
                'id' => $article_id,
            ]);

            $messageLogic = new MessageLogic();
            $messageLogic->delete(session('userId'), $articleData['user_id'], $article_id, MessageType::ARTICLE_COLLECT);

            return success(false);
        }
    }

    /**
     *  获取我的发布
     *
     * @aop    start checkAuth
     * @verify int $is_hide
     * @verify int|null $page
     * @verify int|null $limit
     * @return string
     */
    public function getMyListAction($is_hide, $page = 1, $limit = 10)
    {
        $articleModel = new ArticleModel();
        $articleModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.longitude,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,article_video.url as video,article_video.frame_url");
        $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleModel->setJoin('user', 'user.id= article.user_id');
        $articleModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleModel->setPage($page, $limit);

        $articleModel->addWhere([
            'user.id'         => session('userId'),
            'article.is_hide' => $is_hide,
            'article.is_del'  => 0,
        ]);
        $articleModel->addOrder('article.updated', false);
        $articleModel->addGroup('article.id');
        $data = $articleModel->select();

        return success($data);
    }

    /**
     *  根据用户id获取文章
     *
     * @aop    start checkAuth
     * @verify int $user_id
     * @verify int|null $page
     * @verify int|null $limit
     * @return string
     */
    public function getListByIdAction($user_id, $page = 1, $limit = 10)
    {
        $articleModel = new ArticleModel();
        $articleModel->setFields("article.*,user.username,user.attestation_name,user.avatar_url,user.latitude,user.longitude,user.address_name,user.mobile,one_type.name as one_type_name,one_type.id as one_type_id,GROUP_CONCAT(DISTINCT two_type.name) as two_type_name,GROUP_CONCAT(DISTINCT two_type.id) as two_type_id,GROUP_CONCAT(DISTINCT article_image.url) as images,article_video.url as video,article_video.frame_url");
        $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
        $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
        $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
        $articleModel->setJoin('user', 'user.id= article.user_id');
        $articleModel->setJoin('article_image', 'article_image.article_id= article.id', 'LEFT JOIN');
        $articleModel->setJoin('article_video', 'article_video.article_id= article.id', 'LEFT JOIN');
        $articleModel->setPage($page, $limit);

        $articleModel->addWhere([
            'user.id'         => $user_id,
            'article.is_hide' => 0,
            'article.is_del'  => 0,
        ]);
        $articleModel->addOrder('article.updated', false);
        $articleModel->addGroup('article.id');
        $data = $articleModel->select();

        return success($data);
    }

    /**
     * 更新文章发布时间
     *
     * @aop    start checkAuth
     * @verify int $article_id
     * @return string
     */
    public function updateDateAction($article_id)
    {
        $userModel = new UserModel();
        $data      = $userModel->row([
            'id' => session('userId'),
        ]);
        if (strtotime($data['black_time']) > time()) {
            return fail('由于您最近有违规记录，管理员已对您限制更新，时间持续至' . $data['black_time']);
        }

        $articleModel = new ArticleModel();
        $articleModel->addWhere('updated', now('Y-m-d'), '<');
        $result = $articleModel->update([
            'updated' => now(),
        ], [
            'id'      => $article_id,
            'user_id' => session('userId'),
        ]);

        if (empty($result)) {
            return fail('一天只能更新一次');
        } else {
            return success();
        }
    }

    /**
     * 删除文章
     *
     * @aop    start checkAuth
     * @verify int $article_id
     * @return string
     */
    public function deleteAction($article_id)
    {
        $articleModel = new ArticleModel();
        $result       = $articleModel->update([
            'is_del'  => 1,
            'is_hide' => 1,
        ], [
            'id'      => $article_id,
            'user_id' => session('userId'),
        ]);

        if (empty($result)) {
            return fail('文章不存在');
        } else {
            return success();
        }
    }

    /**
     * 更新文章
     *
     * @aop    start checkAuth
     *
     * @verify int $articleId
     * @verify array|null $images
     * @verify string|null $video
     * @verify string     $content
     * @verify int        $oneTypeId
     * @verify array      $twoTypeId
     * @return string
     */
    public function updateAction($articleId, $images, $video, $content, $oneTypeId, $twoTypeId)
    {
        $userModel = new UserModel();
        $data      = $userModel->row([
            'id' => session('userId'),
        ]);
        if (strtotime($data['black_time']) > time()) {
            return fail('由于您最近有违规记录，管理员已对您限制编辑，时间持续至' . $data['black_time']);
        }

        $articleModel = new ArticleModel();
        $data         = $articleModel->row([
            'id'      => $articleId,
            'user_id' => session('userId'),
        ]);
        if (empty($data)) {
            return fail('请返回重试！');
        }

        $articleModel->update([
            'content' => $content,
            'updated' => now(),
        ], ['id' => $articleId]);

        $imageData = [];
        $images    = is_array($images) ? array_filter($images) : [];
        foreach ($images as $image) {
            if ($image == '') continue;
            $imageData[] = [
                'article_id' => $articleId,
                'created'    => now(),
                'url'        => $image,
            ];
        }

        $articleImageModel = new ArticleImageModel();
        $articleImageModel->delete(['article_id' => $articleId,]);
        if (count($imageData)) {
            $articleImageModel->insert($imageData);
        }

        $articleVideoModel = new ArticleVideoModel();
        $articleVideoModel->delete(['article_id' => $articleId,]);
        if (!empty($video)) {
            $articleVideoModel->insert([
                'article_id' => $articleId,
                'created'    => now(),
                'url'        => $video,
            ]);
        }

        // 添加分类
        // 删除已有分类
        $articleTypeModel = new ArticleTypeModel();
        $articleTypeModel->delete([
            'article_id' => $articleId,
        ]);
        $articleTypes = [];
        foreach ($twoTypeId as $tid) {
            if ($tid == '') continue;
            $articleTypes[] = [
                'article_id'  => $articleId,
                'one_type_id' => $oneTypeId,
                'two_type_id' => $tid,
            ];
        }
        $articleTypeModel->insert($articleTypes);

        return success($articleId);
    }


    /**
     * 检查文章是否有更新
     *
     * @return string
     */
    public function chunkArticleUpdatedAction($id, $time, $version)
    {
        if (!empty($time)) {
            $articleModel = new ArticleModel();
            $articleModel->addWhere('article.updated', $time, '>');
            $articleModel->setFields('article.id');
            $articleModel->setJoin('article_type', 'article.id= article_type.article_id');
            $articleModel->setJoin('user', 'user.id= article.user_id');
            $articleModel->setJoin('one_type', 'one_type.id= article_type.one_type_id');
            $articleModel->setJoin('two_type', 'two_type.id= article_type.two_type_id');
            $articleModel->addWhere('one_type.id', 5, '!=');
            $articleModel->addWhere([
                'article.is_hide'  => 0,
                'one_type.is_hide' => 0,
                'two_type.is_hide' => 0,
                'article.is_del'   => 0,
                'user.type'        => 0,
            ]);
            $data = $articleModel->row();
        } else {
            $data = null;
        }

        if (!empty($data)) {
            return success($data['id']);
        } else {
            return success(false);
        }
    }
}